package com.manhanlou.service;

import com.manhanlou.dao.DiningTableDao;
import com.manhanlou.domain.DiningTable;

import java.util.List;

/**
 * @author wty
 * @date 2022/11/9 10:48
 */
public class DiningTableService {
    private DiningTableDao diningTableDao = new DiningTableDao();

    private DiningTable diningTable = new DiningTable();

    /**
     * 查询显示所有点餐状态
     *
     * @param
     * @return void
     * @date 2022/11/9 11:07
     * @author wty
     **/
    public void queryState() {
        String sqlStr = "SELECT id,state from diningTable";
        List<DiningTable> list = diningTableDao.queryMulti(sqlStr, DiningTable.class);
        System.out.println("餐桌编号\t\t餐桌状态");
        for (DiningTable table : list) {
            System.out.println(table.getId() + "\t\t     " + table.getState());
        }
    }

    /**
     * 订座，查询餐桌状态
     *
     * @param
     * @return void
     * @param: id
     * @date 2022/11/9 11:32
     * @author wty
     **/
    public Object queryDiningTableState(Integer id) {
        // 1.首先检查餐桌是否存在
        String sqlStr = "SELECT state FROM diningTable WHERE id = ?";
        Object o = diningTableDao.queryScalar(sqlStr, id);
        return o;
    }

    /**
     * 订桌:修改diningTable表的状态和订餐人等信息
     *
     * @param
     * @return boolean
     * @param: id
     * @param: orderName
     * @param: orderTel
     * @date 2022/11/9 12:06
     * @author wty
     **/
    public void saveOrder(Integer id, String orderName, String orderTel, String state) {
        String sqlStr = "update diningTable set state = ?,orderName = ?,orderTel = ? where id = ?";
        diningTableDao.dml(sqlStr, state, orderName, orderTel, id);
    }

    /**
     * 订桌:修改diningTable表的状态和订餐人等信息
     *
     * @param
     * @return void
     * @param: id
     * @date 2022/11/9 14:41
     * @author wty
     **/
    public void updateDiningTableState(Integer id, String state) {
        String sqlStr = "update diningTable set state = ? where id = ?";
        diningTableDao.dml(sqlStr, state, id);
    }

}
